<template>
  <div style="position: absolute;width: 100%; top:0;z-index: 99">
    <top-header :title="'购物车'" :hasTitle="true" :hasList="true" :hasCart="false">
      <div style="position: absolute;top:0; right:0rem; height:100%;" @click="deleat">
        <div style="height:100%;line-height: 3rem;vertical-align:middle;color:#EF5423;padding: 0 0.75rem;">
          <span>删除</span>
        </div>

      </div>
    </top-header>
  </div>

</template>
<script>
  import TopHeader from '@/containers/header'
  import {MessageBox} from '@/ui-components'

  export default {
    data() {
      return {}
    },
    components: {
      TopHeader
    },
    methods: {
      deleat() {

        var checkList = this.$store.state.cjy.checkedCartList
        if (checkList.length == 0) {

          MessageBox({title: ' ', message: "请选择想要移除的商品"}).then(

          )
          return
        }


        MessageBox.confirm('删除商品', {title: "删除商品", message: "是否从购物车中移除该商品", cancelButtonText: '再想想'}).then(
          (res) => {
            this.deleFromCart()
          })


      },
      deleFromCart() {
        var sessionId = localStorage.getItem('sessionId')
        sessionId = sessionId == 'undefined' ? '' : sessionId
        var checkList = this.$store.state.cjy.checkedCartList
        var config = {
          shoppingCartList: [],
        }

        if (!checkList || checkList.length == 0) {
          return
        }
        if (sessionId) {
          var shoppingCartList = []
          shoppingCartList = checkList.map(
            (item) => {
              return {rid: item.rid}
            }
          )
          config.shoppingCartList = shoppingCartList
          this.$store.dispatch('cjy/deleCart', config)
        } else {
          var shoppingCartList = checkList.map(
            (item) => {
              return {goodsId: item.goodsId}
            }
          )
          this.$store.commit('cjy/DELE_CART_FROM_LOCAL', shoppingCartList)
        }
      },
      delChose() {
        this.$emit('delChose')
      }
    }
  }
</script>

<style>

</style>
